1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : roleplay/classes/class.roleartefacts.inc.php
5 : - Modulgruppe: Roleplay
6 : - Beschreibung: Verwaltung der Zuordnung von Elementen (Forenbeiträge, Mitteilungen...) zu Rollen.
7 : - Version: 0.4, 14/09/06
8 : - Autor(en): Clemens Weiß <clemens.weiss@mni.fh-giessen.de>
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 : /**
24 : * Verwaltung der Zuordnung von Elementen (Forenbeiträge, Mitteilungen...) zu Rollen.
25 : * @package eStudy.Roleplay
26 : * @version 0.4, 14/09/06
27 : * @author Clemens Weiß <clemens.weiss@mni.fh-giessen.de>
28 : */
29 : if (!defined("FORUM")) define("FORUM", 1);
30 : if (!defined("PM")) define("PM", 2);
31 : if (!defined("ANNOUNCEMENT")) define("ANNOUNCEMENT", 3);
32 : if (!defined("RESSOURCE")) define("RESSOURCE", 4);
33 : if (!defined("NEWS_OF_THE_DAY")) define("NEWS_OF_THE_DAY", 5);
34 : require_once (PATH_TO_ROOT."roleplay/classes/class.role.inc.php");
35 : class RoleArtefacts {
36 : /**
37 : * Gibt zu einem Element (Forumsbeitrag, Private Nachricht, Mitteilung oder Ressource)
38 : * die Rolle zurück, mit der das Element erstellt wurde oder false, wenn der Ersteller
39 : * keine Rolle eingenommen hat, als das Element erstellt wurde.
40 : *
41 : * @static
42 : * @access public
43 : * @param int $cat Kategorie, zu der das Element gehört (FORUM - Forumpost,
44 : * PM - Private Nachricht, ANNOUNCEMENT - Mitteilung,
45 : * RESSOURCE - Link, Datei oder Ordner im Ressourcenmanager,
46 : * NEWS_OF_THE_DAY - NotD-Nachricht eines Kurses)
47 : * @param int $item ID des Elements
48 : * @return mixed Rollenobjekt oder false
49 : */
50 : function getRoleForItem($cat, $item) {
51 0 : global $db, $settings;
52 0 : $dbp = $settings["dbPrefix"];
53 0 : if (!is_integer($cat) || !is_integer($item)) {
54 0 : return false;
55 : }
56 0 : $roleID = intval($db->get_var("SELECT role_id FROM {$dbp}role_artefacts WHERE category='$cat' AND item_id='$item'"));
57 0 : if ($roleID > 0) {
58 0 : return new Role($roleID);
59 : }
60 0 : return false;
61 : }
62 : /**
63 : * Gibt die Element-IDs einer bestimmten Kategorie zurück, die von der angegebenen Rolle angelegt wurden.
64 : *
65 : * @static
66 : * @access public
67 : * @param int $cat Kategorie, zu der das Element gehört (FORUM - Forumpost,
68 : * PM - Private Nachricht, ANNOUNCEMENT - Mitteilung,
69 : * RESSOURCE - Link, Datei oder Ordner im Ressourcenmanager,
70 : * NEWS_OF_THE_DAY - NotD-Nachricht eines Kurses)
71 : * @param int $role Rollen-ID
72 : * @return mixed Array mit den IDs der Elemente oder false
73 : */
74 : function getItemsForRole($cat, $role) {
75 0 : global $db, $settings, $EZSQL_ERROR;
76 0 : $dbp = $settings["dbPrefix"];
77 0 : if (!is_integer($cat) || !is_integer($role)) {
78 0 : return false;
79 : }
80 0 : $items = $db->get_col("SELECT item_id FROM {$dbp}role_artefacts WHERE category='$cat' AND role_id='$role'");
81 0 : if (!is_array($items)) {
82 0 : return array();
83 : }
84 0 : return array_map("intval", $items);
85 : }
86 : /**
87 : * Legt für ein Element (Forumsbeitrag, Private Nachricht, Mitteilung oder Ressource) fest,
88 : * dass es unter Einnahme einer Rolle erstellt wurde.
89 : *
90 : * @static
91 : * @access public
92 : * @param int $cat Kategorie, zu der das Element gehört (FORUM - Forumpost,
93 : * PM - Private Nachricht, ANNOUNCEMENT - Mitteilung,
94 : * RESSOURCE - Link, Datei oder Ordner im Ressourcenmanager,
95 : * NEWS_OF_THE_DAY - NotD-Nachricht eines Kurses)
96 : * @param int $item ID des Elements
97 : * @param int $role ID der Rolle
98 : * @return bool true bei Erfolg, sonst false
99 : */
100 : function setRoleForItem($cat, $item, $role) {
101 0 : global $db, $settings, $EZSQL_ERROR;
102 0 : $dbp = $settings["dbPrefix"];
103 0 : if (!is_integer($cat) || !is_integer($item) || !is_integer($role)) {
104 0 : return false;
105 : }
106 0 : $errorCount = count($EZSQL_ERROR);
107 0 : $db->query("REPLACE INTO {$dbp}role_artefacts SET category='$cat', item_id='$item', role_id='$role'");
108 0 : if (count($EZSQL_ERROR) > $errorCount) {
109 0 : return false;
110 : }
111 0 : return true;
112 : }
113 : /**
114 : * Löscht die Rollenzuordnungen zu einem oder mehreren angegebenen Elementen.
115 : *
116 : * @static
117 : * @access public
118 : * @param int $cat Kategorie, zu der das Element gehört (FORUM - Forumpost,
119 : * PM - Private Nachricht, ANNOUNCEMENT - Mitteilung,
120 : * RESSOURCE - Link, Datei oder Ordner im Ressourcenmanager,
121 : * NEWS_OF_THE_DAY - NotD-Nachricht eines Kurses)
122 : * @param mixed $item ID eines Elements (int) oder Array von IDs
123 : * @return bool true bei Erfolg, sonst false
124 : */
125 : function deleteItem($cat, $item) {
126 0 : global $db, $settings, $EZSQL_ERROR;
127 0 : $dbp = $settings["dbPrefix"];
128 0 : if (!is_integer($cat) || !(is_integer($item) || (is_array($item) && !empty($item)))) {
129 0 : return false;
130 : }
131 0 : if (is_array($item)) {
132 0 : $item = array_map("intval", $item);
133 0 : $itemSQL = "item_id IN (".implode(", ", $item) .")";
134 0 : } else {
135 0 : $itemSQL = "item_id='$item'";
136 : }
137 0 : $errorCount = count($EZSQL_ERROR);
138 0 : $db->query("DELETE FROM {$dbp}role_artefacts WHERE category='$cat' AND $itemSQL");
139 0 : if (count($EZSQL_ERROR) > $errorCount) {
140 0 : return false;
141 : }
142 0 : return true;
143 : }
144 : }
|